package com.foryou.system.modules.wx.controller;

import com.foryou.system.common.utils.R;
import com.foryou.system.modules.wx.entity.PlaceItem;
import com.foryou.system.modules.wx.entity.ShootItem;
import com.foryou.system.modules.wx.entity.WorksItem;
import com.foryou.system.modules.wx.service.PlaceService;
import com.foryou.system.modules.wx.service.ShootService;
import com.foryou.system.modules.wx.service.UserService;
import com.foryou.system.modules.wx.service.WorksService;
import com.foryou.system.modules.wx.vo.MainVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/index")
public class MainController {

    private final UserService userService;

    private final ShootService shootService;

    private final WorksService worksService;

    private final PlaceService placeService;

    public MainController(UserService userService, ShootService shootService, WorksService worksService, PlaceService placeService) {
        this.userService = userService;
        this.shootService = shootService;
        this.worksService = worksService;
        this.placeService = placeService;
    }

    @GetMapping()
    public R index() {
        Map<String, Object> map = new HashMap<>();
        //1.控制面板
        int userTotal = userService.queryTotal(map);
        int shootTotal = shootService.queryTotal(map);
        int worksTotal = worksService.queryTotal(map);
        int placeTotal = placeService.queryTotal(map);

        //2.作品信息集合LIST
        map.put("offset", 0);
        map.put("limit", 8);
        List<WorksItem> worksItemList = worksService.queryList(map);
        map.clear();
        map.put("userTotal", userTotal);
        map.put("shootTotal", shootTotal);
        map.put("worksTotal", worksTotal);
        map.put("placeTotal", placeTotal);
        map.put("worksItemList", worksItemList);

        //3.右侧日历当日审核数
        List<ShootItem> shootItems = shootService.queryNowList();
        long shootCount = shootItems.stream().filter(s -> s.getAuditStatus() == 1).count();

        List<PlaceItem> placeItems = placeService.queryNowList();
        long placeCount = placeItems.stream().filter(s -> s.getAuditStatus() == 1).count();

        List<WorksItem> worksItems = worksService.queryNowList();
        long worksCount = worksItems.stream().filter(s -> s.getAuditStatus() == 1).count();
        return R.ok().put("data",new MainVO(
                userTotal,shootTotal,worksTotal,placeTotal,
                worksItemList,
                shootItems.size(),shootCount,
                placeItems.size(),placeCount,
                worksItems.size(),worksCount
        ));
    }
}
